<template>
  <view>
    <uni-popup ref="popup" type="right" :is-mask-click="false">
      <view class="filter-scroll-view">
        <view class="filter-mask" @click="toggle"></view>
        <view>
          <scroll-view class="scroll-view-box" scroll-y="true">
            <u-gap bgColor="#fff" height="20"></u-gap>
            <view class="cu-filter-item">
              <view class="title">项目编号</view>
              <view class="cu-filter-control">
                <u-input placeholder="输入作业项目编号进行检索" v-model="searchData.projectCode" />
              </view>
            </view>
            <view class="cu-filter-item">
              <view class="title">项目名称</view>
              <view class="cu-filter-control">
                <u-input placeholder="输入作业项目名称进行检索" v-model="searchData.projectName" />
              </view>
            </view>
          </scroll-view>
          <view class="btn-wrap">
            <view class="reset" @click="resetHandler">重置条件</view>
            <view class="confirm" @click="submitHandler">搜索</view>
          </view>
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
export default {
  data() {
    return {
      searchData: {
        projectName: '',
        projectCode: ''
      }
    }
  },
  methods: {
    async toggle() {
      if (this.show) {
        this.show = false
        this.showTime = false
        this.$refs.popup.close()
      } else {
        this.show = true
        this.$refs.popup.open()
        // 时间组件加载耗时，延迟加载
        this.$nextTick(() => {
          setTimeout(() => {
            this.showTime = true
          }, 100)
        })
      }
    },
    resetHandler() {
      this.searchData = {
        projectName: '',
        projectCode: ''
      }
      this.submitHandler()
    },
    submitHandler() {
      this.$emit('submit', this.searchData)
      this.toggle()
    }
  }
}
</script>

<style lang="scss" scoped>
.filter-scroll-view {
  width: 100vw;
  height: 100vh;
  display: flex;

  .filter-mask {
    flex: 1;
  }

  .scroll-view-box {
    width: 672rpx;
    background: #fff;
    box-sizing: border-box;
    height: calc(100vh - 220rpx);
    /* #ifdef APP-PLUS */
    height: calc(100vh - 140rpx);
    /* #endif */
  }

  .btn-wrap {
    background: #fff;
    display: flex;
    justify-content: space-around;
    padding-top: 30rpx;
    padding-bottom: calc(30rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(30rpx + env(safe-area-inset-bottom));

    .reset,
    .confirm {
      width: 292rpx;
      line-height: 80rpx;
      background: #ffffff;
      font-size: 32rpx;
      text-align: center;
    }

    .reset {
      color: #666666;
      background: #ffffff;
      border: 1rpx solid #cccccc;
    }

    .confirm {
      background: #2ac0c8;
      color: #fff;
    }
  }
}

.cu-filter-item {
  padding-bottom: 40rpx;
  .title {
    font-size: 28rpx;
    font-weight: bold;
    color: #333333;
    padding: 0 0 20rpx 30rpx;
  }
  .cu-filter-control {
    padding: 0 30rpx;
  }
}
</style>
